package controllers.basic;

//import controllers.auth.Secure;

import controllers.BaseController;
import controllers.auth.SkipAuth;
import models.merchant.Merchant;
import models.weixin.WebUser;
import order.Order;
import org.apache.commons.collections.map.HashedMap;
import play.mvc.With;
import product.Product;
import product.ProductAccessRecord;
import utils.DateUtil;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 主页
 */

@With(BaseController.class)
public class HomeCtrl extends BaseController {

    /**
     * 主页跳转
     */
    @SkipAuth
    public static void home() {
//        Logger.info("短信发送: %s" ,SendSmsApiWoDong.combinationSendSms("17719330116" , "漫漫人生，我要采撷世间最重的——毅力。  发送时间为:" + DateUtil.dateToString(new Date() , "yyyy-MM-dd HH:mm:ss")));
        Map<String,Object> resultMap = new HashedMap();
        // 最近一个月时间
        Date nowDay = new Date();
        String beginDayStr = DateUtil.getPastDate(nowDay,30);
        Date nowDayEnd = DateUtil.getEndOfDay(nowDay);
        String nowDayEndStr = DateUtil.dateToString(nowDayEnd,"yyyy-MM-dd");
        Date beginBeginDay = DateUtil.stringToDate(beginDayStr + " 00:00:00","yyyy-MM-dd HH:mm:ss");

        // 产品数量
        List<Product> productList = Product.getAllProductList();

        //客户数量
        List<WebUser> webUserList = WebUser.findAvailable();

        //客户数量
        List<Merchant> merchantList = Merchant.findAll();

        //月访问量
        List<ProductAccessRecord> productRecordList = ProductAccessRecord.findYesterdayByProduct(beginBeginDay,nowDayEnd);

        //月成交订单
        List<Order> orderList = Order.findYesterdayByOrder(beginBeginDay,nowDayEnd);

//        //月成交额度
//        List<Map<String,Object>> sumAcountOrder = Order.findSumAcountMapByDate(beginDayStr + " 00:00:00",nowDayEndStr + " 23:59:59");

        //月成交额度
        List<Order> sumAcountOrder = Order.findYesterdayByOrder(beginBeginDay,nowDayEnd);

        Double sumAcount = 0.00;
        for(Order order : sumAcountOrder){
            sumAcount += order.amount;
        }
        long menuId = 0;
//        Integer webUserCount = productList.size()*2;
//        Integer merCount = merchantList.size()*2;
//        Integer recordCount = productRecordList.size()*2;
//        Integer orderCount = orderList.size()*2;
        Double sumAcountCount = sumAcount*2;
//        Integer proCount = productList.size()*2;
        render(webUserList,merchantList,productRecordList,orderList,sumAcountCount,productList,menuId);
    }


}